

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="若发现文章有误，敬请指出，感谢@[TOC]  运行环境  CentOS 7  Hadoop3.3.0 JDK8 Hive 3.1.2  DDL 数据定义操作 数据库DDL操作 增——新增数据库参考资料标准语法： 12345CREATE [REMOTE] (DATABASE|SCHEMA) [IF NOT EXISTS] database_name  [COMMENT database_comme">
<meta property="og:type" content="article">
<meta property="og:title" content="Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列">
<meta property="og:url" content="http://example.com/2022/03/23/Hive%20%E7%AC%94%E8%AE%B01%20DDL%E6%95%B0%E6%8D%AE%E5%AE%9A%E4%B9%89%E6%93%8D%E4%BD%9C%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%20_%20%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%81%E6%95%B0%E6%8D%AE%E8%A1%A8%E3%80%81%E5%88%97/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="若发现文章有误，敬请指出，感谢@[TOC]  运行环境  CentOS 7  Hadoop3.3.0 JDK8 Hive 3.1.2  DDL 数据定义操作 数据库DDL操作 增——新增数据库参考资料标准语法： 12345CREATE [REMOTE] (DATABASE|SCHEMA) [IF NOT EXISTS] database_name  [COMMENT database_comme">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f51827f3642547b992052bc306bca5f5.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/6e0cd3b6938d4b5f85745c43d95213ff.png">
<meta property="article:published_time" content="2022-03-23T11:30:19.000Z">
<meta property="article:modified_time" content="2022-08-22T15:44:41.476Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Hive">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/f51827f3642547b992052bc306bca5f5.png">
  
  
  
  <title>Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-03-23 19:30" pubdate>
          2022年3月23日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          4.9k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          41 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>若发现文章有误，敬请指出，感谢<br>@[TOC]</p>
</blockquote>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>CentOS 7 </li>
<li>Hadoop3.3.0</li>
<li>JDK8</li>
<li>Hive 3.1.2</li>
</ul>
<h1 id="DDL-数据定义操作"><a href="#DDL-数据定义操作" class="headerlink" title="DDL 数据定义操作"></a>DDL 数据定义操作</h1><hr>
<h2 id="数据库DDL操作"><a href="#数据库DDL操作" class="headerlink" title="数据库DDL操作"></a>数据库DDL操作</h2><hr>
<h3 id="增——新增数据库"><a href="#增——新增数据库" class="headerlink" title="增——新增数据库"></a>增——新增数据库</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL">参考资料</a><br><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> [REMOTE] (DATABASE<span class="hljs-operator">|</span>SCHEMA) [IF <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span>] database_name<br>  [COMMENT database_comment]<br>  [LOCATION hdfs_path]<br>  [MANAGEDLOCATION hdfs_path]<br>  [<span class="hljs-keyword">WITH</span> DBPROPERTIES (property_name<span class="hljs-operator">=</span>property_value, ...)];<br></code></pre></td></tr></table></figure>
<p><strong>参数说明：</strong></p>
<table>
<thead>
<tr>
<th align="left">参数</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">COMMENT</td>
<td align="left">对于数据库的描述</td>
</tr>
<tr>
<td align="left">LOCATION</td>
<td align="left">设置数据库位于HDFS的位置</td>
</tr>
<tr>
<td align="left">MANAGEDLOCATION</td>
<td align="left">设置管理数据库的位置</td>
</tr>
<tr>
<td align="left">WITH DBPROPERTIES (property_name&#x3D;property_value, …)</td>
<td align="left">设置更多的数据库参数</td>
</tr>
</tbody></table>
<p>案例：<br><strong>(1) 创建uni数据库</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database uni;<br></code></pre></td></tr></table></figure>
<p><strong>(2) 创建uni数据库，若已存在则不创建</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database uni if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span><br></code></pre></td></tr></table></figure>
<p><strong>(3) 创建uni数据库，并指定其在HDFS里的存储位置</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database uni location <span class="hljs-string">&#x27;/uni.db&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h3 id="删——删除数据库"><a href="#删——删除数据库" class="headerlink" title="删——删除数据库"></a>删——删除数据库</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL">参考资料</a></p>
<p><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DROP</span> (DATABASE<span class="hljs-operator">|</span>SCHEMA) [IF <span class="hljs-keyword">EXISTS</span>] database_name [RESTRICT<span class="hljs-operator">|</span>CASCADE];<br></code></pre></td></tr></table></figure>

<p><strong>案例：</strong><br><strong>(1) 删除之前创建的uni数据库</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">drop</span> database uni;<br></code></pre></td></tr></table></figure>
<p><strong>(2)  删除数据库uni，若不存在则不删除</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">drop</span> database if <span class="hljs-keyword">exists</span> uni;<br></code></pre></td></tr></table></figure>
<p><strong>(3)  删除不为空的数据库，使用CASCADE&#x2F;cascade 强制删除</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">drop</span> database uni cascade;<br></code></pre></td></tr></table></figure>
<h3 id="改——修改数据库"><a href="#改——修改数据库" class="headerlink" title="改——修改数据库"></a>改——修改数据库</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL">参考资料</a><br><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">ALTER</span> (DATABASE<span class="hljs-operator">|</span>SCHEMA) database_name <span class="hljs-keyword">SET</span> DBPROPERTIES (property_name<span class="hljs-operator">=</span>property_value, ...);   <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> SCHEMA added in Hive 0.14.0)</span><br> <br><span class="hljs-keyword">ALTER</span> (DATABASE<span class="hljs-operator">|</span>SCHEMA) database_name <span class="hljs-keyword">SET</span> OWNER [<span class="hljs-keyword">USER</span><span class="hljs-operator">|</span>ROLE] user_or_role;   <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> Hive 0.13.0 and later; SCHEMA added in Hive 0.14.0)</span><br>  <br><span class="hljs-keyword">ALTER</span> (DATABASE<span class="hljs-operator">|</span>SCHEMA) database_name <span class="hljs-keyword">SET</span> LOCATION hdfs_path; <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> Hive 2.2.1, 2.4.0 and later)</span><br> <br><span class="hljs-keyword">ALTER</span> (DATABASE<span class="hljs-operator">|</span>SCHEMA) database_name <span class="hljs-keyword">SET</span> MANAGEDLOCATION hdfs_path; <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> Hive 4.0.0 and later)</span><br></code></pre></td></tr></table></figure>
<p><strong>案例： 修改数据库的描述信息并查看</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> uni;<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">alter</span> database uni <span class="hljs-keyword">set</span> dbproperties(<span class="hljs-string">&#x27;createtime&#x27;</span><span class="hljs-operator">=</span><span class="hljs-string">&#x27;20220323&#x27;</span>);<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">desc</span> database extended uni;<br></code></pre></td></tr></table></figure>
<p><strong>运行结果：</strong><br><img src="https://img-blog.csdnimg.cn/f51827f3642547b992052bc306bca5f5.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="查——查询数据库"><a href="#查——查询数据库" class="headerlink" title="查——查询数据库"></a>查——查询数据库</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-ShowDatabases">参考资料</a><br><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SHOW</span> (DATABASES<span class="hljs-operator">|</span>SCHEMAS) [<span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;identifier_with_wildcards&#x27;</span>];<br></code></pre></td></tr></table></figure>

<p><strong>案例：</strong><br><strong>(1)  显示所有数据库</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">show</span> databases;<br></code></pre></td></tr></table></figure>
<p><strong>(2)  过滤显示的数据库</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> uni;<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">show</span> database <span class="hljs-keyword">like</span> <span class="hljs-string">&#x27;un*&#x27;</span>;<br></code></pre></td></tr></table></figure>
<p><strong>(3) 查看数据库信息</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">desc</span> database uni;<br></code></pre></td></tr></table></figure>
<p><strong>(4) 查看数据库的详细信息</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">desc</span> database extended uni;<br></code></pre></td></tr></table></figure>

<h2 id="切换数据库-内部-x2F-外部"><a href="#切换数据库-内部-x2F-外部" class="headerlink" title="切换数据库(内部&#x2F;外部)"></a>切换数据库(内部&#x2F;外部)</h2><hr>
<p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/Alter/UseDatabase">参考资料</a><br><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql">use database_name;<br><br>use <span class="hljs-keyword">default</span>;<br></code></pre></td></tr></table></figure>

<p><strong>案例：切换到hive提供的默认数据库</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (uni)<span class="hljs-operator">&gt;</span> use <span class="hljs-keyword">default</span>;<br></code></pre></td></tr></table></figure>
<h2 id="结构表DDL操作"><a href="#结构表DDL操作" class="headerlink" title="结构表DDL操作"></a>结构表DDL操作</h2><hr>
<p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/Managed+vs.+External+Tables">参考资料</a></p>
<h3 id="管理表与外部表"><a href="#管理表与外部表" class="headerlink" title="管理表与外部表"></a>管理表与外部表</h3><p>在Hive中数据库的数据表分为两种，分别是 <strong>管理表</strong> 和 <strong>外部表</strong>。</p>
<p>Hive 创建的表默认为 <strong>管理表</strong>，有时称为<strong>内部表</strong>。</p>
<p>对于管理表，Hive会控制其中数据的生命周期，Hive默认情况下会将这些表的数据存储在配置项<br><code>hive.metastore.warehourse.dir</code>中，默认为HDFS里的 <code>/user/hive/warehouse</code> 位置。</p>
<p>管理表和外部表的最大区别就是：当删除管理表（默认）后，其所在的HDFS存储内容也会被删除。</p>
<p>而后者外部表就不会，外部表仅仅会删除元数据，而不会删除HDFS里的完整数据。</p>
<p>这意味着<strong>管理表不适合</strong>跟其他工具共享。</p>
<p><strong>使用场景：</strong> 每天将收集到的网站日志定期流入HDFS文本文件，在<strong>外部表</strong>（原始日志表）的基础上做大量的统计分析，用到的<strong>中间表、结果表</strong>使用<strong>内部表&#x2F;管理表</strong>存储。</p>
<p><strong>案例：分别创建班级和学生外部表，通过HDFS向表中导入数据，之后在hive里删除表，观察HDFS里的表数据是否跟着删除（不会删除HDFS的数据）</strong></p>
<p><strong>(1)  准备原始数据</strong></p>
<p><code>class.txt</code> 班级数据（班级ID、班级号）</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">1</span>	<span class="hljs-number">1</span>	<br><span class="hljs-attribute">2</span>	<span class="hljs-number">2</span><br><span class="hljs-attribute">3</span>	<span class="hljs-number">3</span><br></code></pre></td></tr></table></figure>
<p><code>student.txt</code> 学生数据（学生ID、学生名称、学生年龄、所属班级ID）</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">1</span>	uni	<span class="hljs-number">21</span>	<span class="hljs-number">1</span> <br><span class="hljs-attribute">2</span>	qaq	<span class="hljs-number">20</span>	<span class="hljs-number">2</span><br><span class="hljs-attribute">3</span>	pistar	<span class="hljs-number">18</span>	<span class="hljs-number">3</span><br><span class="hljs-attribute">4</span>	hhh	<span class="hljs-number">20</span>	<span class="hljs-number">1</span><br></code></pre></td></tr></table></figure>
<p><strong>(2) 创建班级和学生的外部表</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">external</span> <span class="hljs-keyword">table</span> if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> class(<br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> id <span class="hljs-type">int</span>, cid <span class="hljs-type">int</span>) <br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-type">row</span> format delimited fields terminated <span class="hljs-keyword">by</span> <span class="hljs-string">&#x27;\t&#x27;</span>;<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">external</span> <span class="hljs-keyword">table</span> if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> student(<br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> id <span class="hljs-type">int</span>, name string, age <span class="hljs-type">int</span>, cid <span class="hljs-type">int</span>) <br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-type">row</span> format delimited fields terminated <span class="hljs-keyword">by</span> <span class="hljs-string">&#x27;\t&#x27;</span>;<br></code></pre></td></tr></table></figure>


<p><strong>(3) 上传本地文件到HDFS</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>)<span class="hljs-operator">&gt;</span> dfs <span class="hljs-operator">-</span>put <span class="hljs-operator">/</span>opt<span class="hljs-operator">/</span><span class="hljs-keyword">module</span><span class="hljs-operator">/</span>hive<span class="hljs-operator">/</span>data<span class="hljs-operator">/</span>class.txt <span class="hljs-operator">/</span><span class="hljs-keyword">user</span><span class="hljs-operator">/</span>hive<span class="hljs-operator">/</span>warehouse<span class="hljs-operator">/</span>class;<br>hive (<span class="hljs-keyword">default</span>)<span class="hljs-operator">&gt;</span> dfs <span class="hljs-operator">-</span>put <span class="hljs-operator">/</span>opt<span class="hljs-operator">/</span><span class="hljs-keyword">module</span><span class="hljs-operator">/</span>hive<span class="hljs-operator">/</span>data<span class="hljs-operator">/</span>student.txt <span class="hljs-operator">/</span><span class="hljs-keyword">user</span><span class="hljs-operator">/</span>hive<span class="hljs-operator">/</span>warehous<span class="hljs-operator">/</span>student;<br></code></pre></td></tr></table></figure>
<p><strong>(4) 查看表以及内容</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">show</span> tables;<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">desc</span> formatted class;<br></code></pre></td></tr></table></figure>
<p><strong>运行结果：</strong><br><img src="https://img-blog.csdnimg.cn/6e0cd3b6938d4b5f85745c43d95213ff.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>查看通过上传到HDFS插入的数据：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> class;<br><br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> student;<br></code></pre></td></tr></table></figure>
<p><strong>运行结果：</strong><br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/85482a1f74644d5383a869a8bf1f68cf.png#">https://img-blog.csdnimg.cn/85482a1f74644d5383a869a8bf1f68cf.png#</a> &#x3D;60%x)<br>可以发现里面出现了NULL，说明原先的文本中有多余的空格，导致Hive识别失败。</p>
<p>此时执行删除表的语句，然后在使用hdfs的命令查看表的内容是否存在</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">drop</span> <span class="hljs-keyword">table</span> class;<br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">drop</span> <span class="hljs-keyword">table</span> student;<br>hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> dfs <span class="hljs-operator">-</span>ls <span class="hljs-operator">/</span><span class="hljs-keyword">user</span><span class="hljs-operator">/</span>hive<span class="hljs-operator">/</span>warehouse<span class="hljs-operator">/</span>;<br></code></pre></td></tr></table></figure>
<p><strong>运行结果：</strong><br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/3806e46e98bf41eba8518e5af26f2f3e.png#">https://img-blog.csdnimg.cn/3806e46e98bf41eba8518e5af26f2f3e.png#</a> &#x3D;60%x)</p>
<h4 id="查询、切换管理表与外部表"><a href="#查询、切换管理表与外部表" class="headerlink" title="查询、切换管理表与外部表"></a>查询、切换管理表与外部表</h4><p><strong>标准语法：</strong></p>
<ul>
<li>查询数据表的类型（内部or外部）<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">desc</span> formatted table_name;<br></code></pre></td></tr></table></figure></li>
<li>修改内部表为外部表<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> table_name <span class="hljs-keyword">set</span> tblproperties(<span class="hljs-string">&#x27;EXTERNAL&#x27;</span><span class="hljs-operator">=</span><span class="hljs-string">&#x27;TRUE&#x27;</span>);<br></code></pre></td></tr></table></figure></li>
<li>修改外部表为内部表<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> table_name <span class="hljs-keyword">set</span> tblproperties(<span class="hljs-string">&#x27;EXTERNAL&#x27;</span><span class="hljs-operator">=</span><span class="hljs-string">&#x27;FALSE&#x27;</span>);<br></code></pre></td></tr></table></figure>
<strong>注：这里的EXTERNAL和值TRUE和FALSE都必须为大写</strong></li>
</ul>
<h3 id="增——新增数据表"><a href="#增——新增数据表" class="headerlink" title="增——新增数据表"></a>增——新增数据表</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable">参考资料</a></p>
<p><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> [REMOTE] (DATABASE<span class="hljs-operator">|</span>SCHEMA) [IF <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span>] database_name<br>  [COMMENT database_comment]<br>  [LOCATION hdfs_path]<br>  [MANAGEDLOCATION hdfs_path]<br>  [<span class="hljs-keyword">WITH</span> DBPROPERTIES (property_name<span class="hljs-operator">=</span>property_value, ...)];<br></code></pre></td></tr></table></figure>
<p><strong>案例：</strong><br><strong>(1) 创建表（默认为管理表）</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> uni(id <span class="hljs-type">int</span>, name string);<br></code></pre></td></tr></table></figure>

<p><strong>(2) 根据表uni的查询结果创建表student</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> student <span class="hljs-keyword">as</span> <span class="hljs-keyword">select</span> id, name <span class="hljs-keyword">from</span> uni;<br></code></pre></td></tr></table></figure>
<p><strong>(3) 根据已存在的表student结构创建空表</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">hive (<span class="hljs-keyword">default</span>) <span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> if <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> student2 <span class="hljs-keyword">like</span> student;<br></code></pre></td></tr></table></figure>
<h3 id="删——删除数据表"><a href="#删——删除数据表" class="headerlink" title="删——删除数据表"></a>删——删除数据表</h3><p><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> table_name<br></code></pre></td></tr></table></figure>

<h3 id="改——修改数据表"><a href="#改——修改数据表" class="headerlink" title="改——修改数据表"></a>改——修改数据表</h3><p><strong>标准语法：</strong></p>
<ul>
<li>修改表名：<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> [IF <span class="hljs-keyword">EXISTS</span>] table_name [PURGE]; <br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id=""><a href="#" class="headerlink" title=""></a></h2><h2 id="列DDL操作"><a href="#列DDL操作" class="headerlink" title="列DDL操作"></a>列DDL操作</h2><hr>
<h3 id="增删——新增-x2F-删除列"><a href="#增删——新增-x2F-删除列" class="headerlink" title="增删——新增&#x2F;删除列"></a>增删——新增&#x2F;删除列</h3><p><a target="_blank" rel="noopener" href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn">参考资料</a><br><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name <br>  [<span class="hljs-keyword">PARTITION</span> partition_spec]                 <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> Hive 0.14.0 and later)</span><br>  <span class="hljs-keyword">ADD</span><span class="hljs-operator">|</span>REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...)<br>  [CASCADE<span class="hljs-operator">|</span>RESTRICT]                         <span class="hljs-comment">-- (<span class="hljs-doctag">Note:</span> Hive 1.1.0 and later)</span><br></code></pre></td></tr></table></figure>
<p>ADD表示新增一个字段，字段位置在所有列后面（除partition列外）。</p>
<p>REPLACE则是表示替换表中所有字段，当选择该配置且后面的COLUMNS为空时，则表示为删除所有列</p>
<h3 id="改——修改列"><a href="#改——修改列" class="headerlink" title="改——修改列"></a>改——修改列</h3><p><strong>标准语法：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name [<span class="hljs-keyword">PARTITION</span> partition_spec] CHANGE [<span class="hljs-keyword">COLUMN</span>] col_old_name col_new_name column_type<br>  [COMMENT col_comment] [<span class="hljs-keyword">FIRST</span><span class="hljs-operator">|</span>AFTER column_name] [CASCADE<span class="hljs-operator">|</span>RESTRICT];<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93/" class="category-chain-item">数据仓库</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Hive/">#Hive</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列</div>
      <div>http://example.com/2022/03/23/Hive 笔记1 DDL数据定义操作常用命令 _ 增删改查数据库、数据表、列/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年3月23日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/03/25/Hive%20%14%EF%BF%BD2%20%7F(%EF%BF%BD%EF%BF%BD%EF%BF%BDpover%EF%BF%BD%EF%BF%BD5F8%EF%BF%BD%EF%BF%BD*%00B_%20%EF%BF%BD%EF%BF%BD%EF%BF%BD*%EF%BF%BD%1F-p%C7%84~%EF%BF%BD%EF%BF%BD%EF%BF%BD;%EF%BF%BDp_%20~%EF%BF%BD-p%0E%EF%BF%BD%EF%BF%BD%EF%BF%BD;%EF%BF%BD%20_%20%09g%EF%BF%BD%1F%EF%BF%BD%EF%BF%BD9%EF%BF%BDL/%EF%BF%BD%20_%EF%BF%BD%EF%BF%BD~%EF%BF%BD%0A!-p%EF%BF%BD%EF%BF%BD%20_%20%EF%BF%BD%EF%BF%BDM20%25%EF%BF%BD%EF%BF%BD/" title="Hive 笔记2 使用窗口函数over实现电商常见五个需求_ 查询某个时期购买过的顾客以及总人数_ 顾客购买明细以及总额 _ 按照日期对花费进行累加 _查询顾客上次购买时间 _ 查询前20%时间">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hive 笔记2 使用窗口函数over实现电商常见五个需求_ 查询某个时期购买过的顾客以及总人数_ 顾客购买明细以及总额 _ 按照日期对花费进行累加 _查询顾客上次购买时间 _ 查询前20%时间</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/03/21/Flume%20%E7%AC%94%E8%AE%B04%20%E8%87%AA%E5%AE%9A%E4%B9%89Source%20%E4%B8%8E%20%E8%87%AA%E5%AE%9A%E4%B9%89%20Sink%20%E6%A1%88%E4%BE%8B%E4%BB%A5%E5%8F%8A%E6%B5%8B%E8%AF%95/" title="Flume 笔记4 自定义Source 与 自定义 Sink 案例以及测试">
                        <span class="hidden-mobile">Flume 笔记4 自定义Source 与 自定义 Sink 案例以及测试</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
